package com.larry.mr.inputformat;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.BytesWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;
import org.apache.hadoop.mapreduce.lib.output.SequenceFileOutputFormat;

import java.io.IOException;

/**
 * @ProjectName map-reduce
 * @Author larry
 * @Date 20:35 2022/3/30
 * @Description TODO
 **/
public class SequenceFileDriver {
    public static void main(String[] args) throws Exception {

        Configuration conf = new Configuration();
        Job job = Job.getInstance(conf);

        job.setJarByClass(SequenceFileDriver.class);

        job.setMapperClass(SequenceFileMapper.class);
        job.setReducerClass(SequenceFileReducer.class);

        //设置输入的inputformat
        job.setInputFormatClass(WholeFileInputFormat.class);
        //设置输出的outputformat
        job.setOutputFormatClass(SequenceFileOutputFormat.class);

        job.setMapOutputKeyClass(Text.class);
        job.setMapOutputValueClass(BytesWritable.class);

        job.setOutputKeyClass(Text.class);
        job.setOutputValueClass(BytesWritable.class);

        FileInputFormat.setInputPaths(job,new Path("/Users/larry/IdeaProjects/map-reduce/src/main/resources/input2"));
        FileOutputFormat.setOutputPath(job,new Path("/Users/larry/IdeaProjects/map-reduce/src/main/resources/output2"));

        boolean result = job.waitForCompletion(true);
        System.out.println(result);
    }
}
